package com.tbs.parkingsaleapp.SystemManager;

import abstergo.tbs.betterasyc.Handler.HandlerMananger;
import abstergo.tbs.betterasyc.Handler.IHandlerAction;
import android.content.Context;
import android.os.Message;
import com.tbs.parkingsaleapp.SystemManager.Handler.HandlerConst;
import net.steamcrafted.loadtoast.LoadToast;

public class LoadToastMananger {
    static LoadToast toast;
    private static final int ERRORDELAY = 2000,HIDEDELAY=500;
    static boolean needtoHide=false,okToHide=false;

    public static class LoadToastDelayer implements IHandlerAction
    {

        @Override
        public void Handle(Message rawmsg) {
            okToHide=true;
            if(needtoHide)
                toast.hide();
        }
    }
    public static class  LoadToastAutoHider implements IHandlerAction
    {
        @Override
        public void Handle(Message rawmsg) {
            toast.hide();
        }
    }


    public static void Show(Context context, String text,int offset)
    {
        toast=new LoadToast(context);
        toast.setText(text);
        toast.setTranslationY(offset);
        toast.show();
        needtoHide=false;
        okToHide=false;
        Message msg=new Message();
        msg.what=HandlerConst.TOAST_HIDE;
        Message de=new Message();
        de.what=HandlerConst.TOAST_DELAY;
        HandlerMananger.Instance().SendMsg(msg,ERRORDELAY).SendMsg(de,ERRORDELAY);
    }
    public static void Hide()
    {
        needtoHide=true;
        if(toast!=null)
        {
            if(okToHide)
                toast.hide();
        }
    }
}
